package com.betfair.wrapper.types;

import com.betfair.www.publicapi.types.global.v3.BFEvent;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: markwilliams
 * Date: 10/18/13
 * Time: 10:17 PM
 * To change this template use File | Settings | File Templates.
 */

@Entity
@Table(name = "Event", uniqueConstraints = {
        @UniqueConstraint(columnNames = "iEventId")})
public class Event {
    int _id = 0;
    String _menuLevel1;
    String _menuLevel2;
    String _menuLevel3;
    String _menuLevel4;
    BFEvent _event = new BFEvent();
    Set<MarketSummaryWrap> _marketSummary = new HashSet<MarketSummaryWrap>();
    Set<MarketWrap> _market = new HashSet<MarketWrap>();

    public Event() {
    }

    public Event(BFEvent _event) {
        this._event = _event;
    }

    @Transient
    public MarketWrap getMarket(int marketId) {
        for (MarketWrap marketWrap : this._market) {
            if (marketWrap.getMarketId() == marketId) {
                return marketWrap;
            }
        }
        return null;
    }

    @Id
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
    @Column(name = "iEventId")
    public int getId() {
        return _id;
    }

    public void setId(int id) {
        this._id = id;
    }

    @Column
    public int getEventId() {
        return _event.getEventId();
    }

    public void setEventId(int param) {
        _event.setEventId(param);
    }

    @Column
    public String getEventName() {
        return _event.getEventName();
    }

    public void setEventName(String param) {
        _event.setEventName(param);
    }

    @Column
    public int getEventTypeId() {
        return _event.getEventTypeId();
    }

    public void setEventTypeId(int param) {
        _event.setEventTypeId(param);
    }

    @Column
    public int getMenuLevel() {
        return _event.getMenuLevel();
    }

    public void setMenuLevel(int param) {
        _event.setMenuLevel(param);
    }

    @Column
    public int getOrderIndex() {
        return _event.getOrderIndex();
    }

    public void setOrderIndex(int param) {
        _event.setOrderIndex(param);
    }

    public String getTimezone() {
        return _event.getTimezone();
    }

    public void setTimezone(String param) {
        _event.setTimezone(param);
    }

    public String getMenuLevel1() {
        return _menuLevel1;
    }

    public void setMenuLevel1(String menuLevel1) {
        this._menuLevel1 = menuLevel1;
    }

    public String getMenuLevel2() {
        return _menuLevel2;
    }

    public void setMenuLevel2(String menuLevel2) {
        this._menuLevel2 = menuLevel2;
    }

    public String getMenuLevel3() {
        return _menuLevel3;
    }

    public void setMenuLevel3(String menuLevel3) {
        this._menuLevel3 = menuLevel3;
    }

    public String getMenuLevel4() {
        return _menuLevel4;
    }

    public void setMenuLevel4(String menuLevel4) {
        this._menuLevel4 = menuLevel4;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    public Set<MarketSummaryWrap> getMarketSummary() {
        return _marketSummary;
    }

    public void setMarketSummary(Set<MarketSummaryWrap> marketSummary) {
        this._marketSummary = marketSummary;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    public Set<MarketWrap> getMarket() {
        return _market;
    }

    public void setMarket(Set<MarketWrap> market) {
        this._market = market;
    }
}
